package calculatorController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.StringTokenizer;

import javax.swing.JButton;

import calculatorModel.Div;
import calculatorModel.Operation;
import calculatorView.CalculatorArea;

public class DivButton extends JButton {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Operation operator;
	private CalculatorArea area;

	public DivButton(Operation operator, CalculatorArea area) {
		super();
		this.operator = operator;
		this.area = area;
		this.setText("/");
		setDivButton();
	}

	private void setDivButton() {

		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				String espression = area.getArea().getText();

				StringTokenizer strtok = new StringTokenizer(espression, " ");
				int verifySeq = strtok.countTokens();

				if (verifySeq == 1) {

					area.getArea().append(" / ");
					operator.setOperator(new Div());
				}
			}
		});

	}

}
